package com.domain;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;


/**
 * ���� 
 * ʱ�� 2017-10-23 20:23
 * ���� Ф����
 */
@SuppressWarnings({"rawtypes","all"})
public class CircularQueueV2 extends CircularQueue {
	
	
	public void enQueueV2(Task task) {
		if (isFull() == false) {
			int newRear = 0;
			newRear = (task.getIndex() + rear) % length;
			HashSet set = (HashSet) this.queueList[newRear];
			if(set == null){
				set = new HashSet<Task>();
			}
			set.add(task);
			this.queueList[newRear] = set;
			rear ++;
		} else {
			System.out.println("ERROR:enQueueV2 is Full");
			return;
		}
	}
	
	public void outQueueV2() {
		if (isEmpty() == false) {
			front = (front + 1) % length;
		} else {
			System.out.println("ERROR:Queue is Empty");
			return;
		}
	}
	
	public Set<Task> queueFrontV2() {
		HashSet getFront = null;
		if (isEmpty() == false) {
			getFront = (HashSet) queueList[(front + 1) % length];
		} else {
			System.out.println("ERROR:queueFrontV2 is Empty");
		}
		return getFront;
	}

	@Override
	public String toString() {
		return "CircularQueueV2 [length=" + length + ", front=" + front
				+ ", rear=" + rear + ", queueList="
				+ Arrays.toString(queueList) + ", queueFrontV2()="
				+ queueFrontV2() + ", isEmpty()=" + isEmpty() + ", isFull()="
				+ isFull() + ", queueFront()=" + queueFront() + ", getClass()="
				+ getClass() + ", hashCode()=" + hashCode() + ", toString()="
				+ super.toString() + "]";
	}
	
	
}
